﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.ServiceProcess;
using System.Text;
using System.Threading;
using WindowsServiceTest;

namespace WindowsService1
{
    public partial class Service1 : ServiceBase
    {
        public Service1()
        {
            InitializeComponent();
        }
        StreamWriter sw = new StreamWriter("D:\\111.log", true);
        protected override void OnStart(string[] args)
        {
            var currentFileName = Assembly.GetExecutingAssembly().Location;
            //ProcessAsUserHelper.ShowMessageBox(currentFileName + "|" + Path.GetFileName(currentFileName) + "|" + Path.GetDirectoryName(currentFileName), "提示");
            ////ProcessAsUserHelper.CreateProcessAsUser(@"SiMayRemoteMonitor.exe", @"C:\Users\Administrator\Desktop\SiMayRemoteMonitor 3.0\Bin\", "img");
            ////WinAPI_Interop.CreateProcess(
            //string s;
            //var r = MyClass.Start("img", "", out s);


            //    ProcessAsUserHelper.ShowMessageBox("状态:"+r.ToString()+" | "+s, "提示");

            var currentPath = Assembly.GetExecutingAssembly().Location;
            string msg = ProcessAsUserHelper.CreateProcessAsUser(Path.GetFileName(currentPath), Path.GetDirectoryName(currentPath), "img");
            ProcessAsUserHelper.ShowMessageBox(msg, "过程信息!");
            if (string.IsNullOrEmpty(msg))
                Environment.Exit(0);
            new Thread(() =>
            {
                for (int i = 0; i < 10000000; i++)
                {
                    Console.WriteLine(DateTime.Now);
                    sw.WriteLine(DateTime.Now);
                    sw.Flush();
                    Thread.Sleep(1000);
                }
            }).Start();
        }

        protected override void OnStop()
        {
        }
    }
}
